<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="java.util.*"%>

<%@ page import="javax.servlet.jsp.tagext.TryCatchFinally"%>
<%@ page import="web1.bean.user"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
	<h1>测试JSTL标签库</h1>
	<ul>
		<li>采用c:out标签</li> hello(使用标签)
		<c:out value="123"></c:out>
		<br> hello(使用标签,结合el表达式)
		<c:out value="${hello }"></c:out>
		<br> hello(使用el表达式)${hello }
		<br> hello(使用el表达式,default)${hello123 }
		<br> hello(使用标签,结合el表达式,缺省值)
		<c:out value="${hello123 }" default="hello123"></c:out>
		<br> hello(使用标签,结合el表达式，缺省值)
		<c:out value="${hello123 }">hello123</c:out>
		<br> welcome(使用el表达式)${welcome }
		<br> welcome(使用标签,escapeXml=true,缺省值)
		<c:out value="${welcome }" escapeXml="true"></c:out>
		<br> welcome(使用标签,escapeXml=false，缺省值)
		<c:out value="${welcome }" escapeXml="false"></c:out>
		<br>
		<hr>
		<li>测试c:set 和 c:remove</li>
		<c:set value="xh" var="userId"></c:set>
		<br> userId:${userId }
		<br>
		<c:remove var="userId" />
		<br> userId:${userId }
		<br>
		<hr>
		<li>条件控制标签：--->c:if</li>
		<c:if test="${v2 lt v1 }">
          0 <br>
		</c:if>
		<hr>
		<li>条件控制标签：c:choose,c:when,c:otherwise</li>
		<c:choose>
			<c:when test="${v1 gt v2 }">
              v1大于v2<br>
			</c:when>
			<c:otherwise>
              v1小于v2<br>
			</c:otherwise>
		</c:choose>

		<c:choose>

			<c:when test="${empty userList }">
          没有符合条件的数据<br>
			</c:when>
			<c:otherwise>
              存在用户数据<br>
			</c:otherwise>
		</c:choose>
		<hr>
		<li>循环控制标签：--->c:forEach</li>
		<h3>采用jsp脚本显示</h3>

		<table border="1px">
			<tr>
				<td>用户姓名</td>
				<td>用户年龄</td>
				<td>所属组</td>
			</tr>
			<%
				List userList = (List) request.getAttribute("users");
				if (userList == null || userList.size() == 0) {
			%>
			<tr>
				<td colspan="3">没有符合条件的数据</td>
			</tr>
			<%
				} else {
					for (Iterator iter = userList.iterator(); iter.hasNext();) {
						user u = (user) iter.next();
			%>
			<tr>
				<td><%=u.getName()%></td>
				<td><%=u.getAge()%></td>
				<td><%=u.getGroup().getName()%></td>
			</tr>

			<%
				}
				}
			%>
		</table>
		<h3>采用c:forEach 标签</h3>
		<table border="1px">
			<tr>
				<td>用户姓名</td>
				<td>用户年龄</td>
				<td>所属组</td>
			</tr>
			<c:choose>
				<c:when test="${empty users }">
					<tr>
						<td colspan="3">没有符合条件的数据</td>
					</tr>
				</c:when>
				<c:otherwise>
					<c:forEach items="${users }" var="user">
						<tr>
							<td>${u.name }</td>
							<td>${u.age }</td>
							<td>${u.group.name }</td>
						</tr>
					</c:forEach>
				</c:otherwise>
			</c:choose>
		</table>
		<h3>采用c:forEach ,varstatus</h3>
		<table border="1px">
			<tr>
				<td>用户姓名</td>
				<td>用户年龄</td>
				<td>所属组</td>
			</tr>
			<c:choose>
				<c:when test="${empty users }">
					<tr>
						<td colspan="3">没有符合条件的数据</td>
					</tr>
				</c:when>
				<c:otherwise>
					<c:forEach items="${users }" var="user" varStatus="vs">
						<c:choose>
							<c:when test="${vs.count mod 2==0 }">
								<tr bgcolor="red">
							</c:when>
							<c:otherwise>
								<tr>
							</c:otherwise>
						</c:choose>
						<td>${u.name }</td>
						<td>${u.age }</td>
						<td>${u.group.name }</td>
						</tr>
					</c:forEach>

				</c:otherwise>
			</c:choose>
		</table>
		<li>循环控制标签forEach：输出map</li>
		<c:forEach items="${map }" var="entry">
          ${entry.key } ,${entry.value } <br>
		</c:forEach>
		<li>循环控制标签forTokens</li>
		<c:forTokens items="${strTokens} " delims="#" var="v">
          ${v } <br>
		</c:forTokens>
		<li>c:catch标签</li>
		<p>
			<%
				try {
					Integer.parseInt("ahk");
				} catch (Exception e) {
					out.println(e.getMessage());
				}
			%>
		</p>
		<P>
			<c:catch var="msg">
				<%
					Integer.parseInt("ahk");
				%>
			</c:catch>
	  ${msg }	
		<P>
	</ul>
</body>
</html>